﻿#region Copyright & licence

// This file is part of Refix.
// 
// Refix is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// Refix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with Refix.  If not, see <http://www.gnu.org/licenses/>.
// 
// Copyright (C) 2010-11 David Musgrove and others.

#endregion

using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;

using NUnit.Framework;

using Refix.Core.Commands;

namespace Refix.Core.Tests
{
    [TestFixture]
    public class LocalisationTest
    {
        private string _solutionRootDirectory;

        [TestFixtureSetUp]
        public void TextFixtureSetUp()
        {
            var fileInfo = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            _solutionRootDirectory = fileInfo.Directory.Parent.Parent.Parent.FullName;
        }

        [Test]
        public void Culture_Selected_Correct_Resource_File()
        {
            var builder = new StringBuilder();
            OutputWriter.Writer = new StringWriter(builder);
            OutputWriter.Verbository = OutputVerbosity.Quiet;
            Directory.SetCurrentDirectory(Path.Combine(_solutionRootDirectory, "Refix.TestSolution"));

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr-FR");

            Command version = new CommandWithOptions(new[] {"version"}).Command;
            version.Execute();

            StringAssert.Contains("et autres", builder.ToString(),
                                  "French 'et autres' not found in output.");
        }
    }
}